package main

import "fmt"

func factorial(num int) int {
	result := 1
	for ; num > 0; num-- {
		result *= num
	}
	return result
}

func factorial1(num int) int {
	if num == 1 {
		return num
	} else {
		return (num) * factorial1(num-1)
	}
}

// 尾递归优化
func factorial2(num, accumulator int) int {
	if num == 1 {
		return accumulator
	} else {
		return factorial2(num-1, accumulator*num)
	}
}

// 斐波那切数列
func fibonacci(num int) {

	a, b := 0, 1
	calc := func() int {
		a, b = b, a+b
		return a
	}
	for ; num > 0; num-- {
		fmt.Println(calc())
	}
}

func main() {
	// fmt.Println(factorial(10))
	// fmt.Println(factorial1(10))
	// fmt.Println(factorial2(10, 1))
	fibonacci(10)
}
